package com.space.product.service;

import com.space.client.api.ProductService;
import com.space.client.dto.ProductInfoDTO;
import com.space.product.assembler.ProductInfoAssembler;
import com.space.product.domain.info.service.ProductInfoDomainService;
import com.space.product.domain.info.valueobject.ProductId;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

/**
 * @author <a href="mailto:414563035@qq.com">Bedroom</a>
 * @date 2021/4/17 7:19 下午
 */
@DubboService
@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    ProductInfoAssembler productInfoAssembler;

    @Autowired
    ProductInfoDomainService productInfoDomainService;

    @Override
    public Mono<ProductInfoDTO> getProductInfo(Integer productId) {
        return productInfoDomainService.getProductInfo(new ProductId(productId))
                .map(productInfo -> productInfoAssembler.toDTO(productInfo));
    }
}
